package packets;

import java.io.ObjectInputStream.GetField;

import org.jnetpcap.nio.JBuffer;
import org.jnetpcap.packet.JHeader;
import org.jnetpcap.packet.JPacket;
import org.jnetpcap.packet.annotate.Bind;
import org.jnetpcap.packet.annotate.Field;
import org.jnetpcap.packet.annotate.Header;
import org.jnetpcap.packet.annotate.HeaderLength;


@Header(name="OSPFHello", description="OSPFHeader")
public class OSPFHello extends JHeader {

private int numberOfNeighbors = 0; // gibt an wieviele Nachbarn in diesem HelloPacket vermerkt sind


@Field(offset=0, length = 4)
public String networkMask(){
	return getUTF8String(0, 4);
}
	
@Field(offset=4*8, length = 2*8)
public byte[] helloIntervall(){
	return getByteArray(0, 2);
}

@Field(offset= 6*8, length = 1*8)
public String options(){
	return getUTF8String(2, 1);  
}

@Field(offset = 7*8, length=1*8)
public int routerPriority(){
	return getUByte(7);
}

@Field(offset = 8*8, length=4*8)
public int deadInterval(){
	return getUByte(8);
}

@Field(offset = 12*8, length=4*8)
public byte[] designatedRouter(){
	return getByteArray(12, 4);
}

@Field(offset = 16*8, length = 4*8)
public byte[] backupDesignatedRouter(){
	return getByteArray(16, 4);
}

@Field(offset = 20*8)
public byte[] neighbors(){
	return getByteArray(20, numberOfNeighbors*4);
}




	@Bind(to=OSPF.class)
	public static boolean bindToOSPF(JPacket packet, OSPF ospf){
		return ospf.type() == 0x01;
	}
	
	@HeaderLength
	public static int headerLength(JBuffer buffer, int offset){
		return buffer.size() - offset;
	}

	@Override
	protected void decodeHeader() {
				this.numberOfNeighbors = (this.getHeaderLength() - 20) / 4;
		}
	

	

}
